package com.molin.IOtest.charstreamTest;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;

public class Demo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
//        method1();
        method2();

    }

    public static void method2() throws UnsupportedEncodingException {
        //utf-8
        byte[] bytes1={-26, -78, -85, -26, -98, -105, -25, -88, -117, -27, -70, -113, -27, -111, -104};
        //gbk
        byte[] bytes2={-60, -83, -63, -42, -77, -52, -48, -14, -44, -79};

        //利用默认的utf-8进行解码
        String s1=new String(bytes1);
        System.out.println(s1);
        //利用默认的GBK进行解码
        String s2=new String(bytes2,"gbk");
        System.out.println(s2);
    }


    public static void method1() throws UnsupportedEncodingException {
        String s="沫林程序员";
        //利用idea默认的utf-8将中文编码为一系列字节
        byte[] bytes=s.getBytes();
        System.out.println(Arrays.toString(bytes));

        byte[] bytes1=s.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1));
    }
}
